/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.tool.utils;

/**
 * Helper class for disabling verbose logs generated by XWiki during the XAR import.
 *
 * @version $Id$
 * @since 6.2M2
 */
public final class LogUtils
{
    private static final String INFO_LEVEL = "info";

    private static final String WARN_LEVEL = "warn";

    private static final String ERROR_LEVEL = "error";

    private LogUtils()
    {
        // Forbid instantiation of utility class
    }

    /**
     * If running under Maven 3.1+, where slf4j-simple is used as the logging backend, configure the SLF4J simple to
     * have proper logging levels that do not generate too many logs.
     */
    public static void configureXWikiLogs()
    {
        // Note 1: This line doesn't have always effect, depending on the version of Maven used. It's probably because
        // Maven overwrite this system property.
        // Note 2: With Maven >= 3.1 and <= 3.2.2, calling System.setProperty("org.slf4j.simpleLogger.defaultLogLevel")
        // returns the proper default logging level. However with Maven >= 3.2.3 calling
        // System.setProperty("org.slf4j.simpleLogger.defaultLogLevel") returns null for some reason.
        System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", WARN_LEVEL);

        // Explicitly configure the logging levels for various packages
        System.setProperty("org.slf4j.simpleLogger.log.org", WARN_LEVEL);
        System.setProperty("org.slf4j.simpleLogger.log.org.xwiki", INFO_LEVEL);
        System.setProperty("org.slf4j.simpleLogger.log.hsqldb", WARN_LEVEL);

        // Explicitly ignore warnings about the logback system, since under Maven 3.1+ the logging framework used is
        // slf4j-simple
        System.setProperty("org.slf4j.simpleLogger.log.org.xwiki.logging.logback", ERROR_LEVEL);
    }
}
